package com.gexiaobao.pigeon.ui.adapter

import android.annotation.SuppressLint
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.base.DataBindBaseViewHolder
import com.gexiaobao.pigeon.app.model.bean.BloodPigeonListBean
import com.gexiaobao.pigeon.app.util.ImageLoaderManager
import com.gexiaobao.pigeon.databinding.ItemBloodPigeonBinding

/**
 * @Author      : hxw
 * @Date        : 2024/8/23 17:13
 * @Describe    :
 */
class AdapterBloodPigeon(data: ArrayList<BloodPigeonListBean>) :
    BaseQuickAdapter<BloodPigeonListBean, DataBindBaseViewHolder>(R.layout.item_blood_pigeon, data) {
    @SuppressLint("ResourceAsColor")
    override fun convert(holder: DataBindBaseViewHolder, item: BloodPigeonListBean) {
        val binding = DataBindBaseViewHolder.getBinding(holder) as ItemBloodPigeonBinding
        binding.data = item
        binding.executePendingBindings()

        val ivCover = holder.getView<AppCompatImageView>(R.id.ivItemImageView)
        ImageLoaderManager.loadRoundImageOrEmpty(context, item.img, ivCover, 8, R.mipmap.app_icon_)

        val sexBg: Int
        val sexColor: Int
        when (item.sex) {
            "雌" -> {
                sexBg = R.drawable.border_red3
                sexColor = R.color.color_f65a5a
            }

            "雄" -> {
                sexBg = R.drawable.border_99cc3
                sexColor = R.color.dodgerblue
            }

            else -> {
                sexBg = R.drawable.border_gray3
                sexColor = R.color.comm_text_gray_light
            }
        }
        holder.setBackgroundResource(R.id.tvItemPigeonSex, sexBg)
        holder.setTextColor(R.id.tvItemPigeonSex, ContextCompat.getColor(context, sexColor))
    }
}